
import { axios } from '@/service/service'
import {
  CodeReq,
  CodesReq,
  NameReq,
  ReleaseStateReq,
  LimitReq,
  PageReq,
  ListReq,
  ProcessDefinitionReq,
  TargetCodeReq,
  singleIdReq,
  VersionReq,
  definitionPageReq
} from './types'

// 复制作业流
export function batchCopyByCodes(params: singleIdReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/copyProcess`,
    method: 'get',
    params
  })
}


// 删除作业流
export function deleteByCode(params: singleIdReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/delProcess`,
    method: 'get',
    params
  })
}


// 删除作业流版本
export function deleteVersion(params: singleIdReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/delVersion`,
    method: 'get',
    params
  })
}


// 查询作业流版本明细
export function findProcessLogDtl(params: VersionReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/findProcessLogDtl`,
    method: 'get',
    params
  })
}


// 查询作业流版本列表
export function queryVersions(params: VersionReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/findProcessLogs`,
    method: 'get',
    params
  })
}
// 查询作业流定义列表
export function queryListPagingReq(params: definitionPageReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/findProcesses`,
    method: 'get',
    params
  })
}
// 作业流上下线
export function release(params: singleIdReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/release`,
    method: 'get',
    params
  })
}

// 查询作业流节点集合
export function queryTaskNodes(params: singleIdReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/queryTaskNodes`,
    method: 'get',
    params
  })
}

// 创建或更新作业流程
export function createProcessDefinition(params: any): any {
  return axios({
    url: `/api-scheduler/processDefinition/saveOrUpdateProcess`,
    method: 'post',
    params
  })
}

// 设置作业流owners
export function setOwners(params: singleIdReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/setOwners`,
    method: 'post',
    params
  })
}

// 作业流版本切换
export function switchVersion(params: singleIdReq): any {
  return axios({
    url: `/api-scheduler/processDefinition/switchVersion`,
    method: 'get',
    params
  })
}

//  树形图
export function viewTreeReq(
  params: singleIdReq,
  code: number
  ): any {
  return axios({
    url: `/api-scheduler/processDefinition/${code}/view-tree`,
    method: 'get',
    params
  })
}


// ------------ 分割线 ------------------------------------------


// 树形图
export function viewTree(
  code: number,
  processCode: number,
  params: LimitReq
): any {
  return axios({
    url: `/projects/${code}/process-definition/${processCode}/view-tree`,
    method: 'get',
    params
  })
}

export function queryListPaging(params: PageReq & ListReq, code: number): any {
  return axios({
    url: `/projects/${code}/process-definition`,
    method: 'get',
    params
  })
}



export function queryProcessDefinitionList(projectCode: number): any {
  return axios({
    url: `/projects/${projectCode}/process-definition/query-process-definition-list`,
    method: 'get'
  })
}



export function batchDeleteByCodes(data: CodesReq, code: number): any {
  return axios({
    url: `/projects/${code}/process-definition/batch-delete`,
    method: 'post',
    data
  })
}

export function batchExportByCodes(data: CodesReq, code: number): any {
  return axios({
    url: `/projects/${code}/process-definition/batch-export`,
    method: 'post',
    responseType: 'blob',
    data
  })
}

export function batchMoveByCodes(
  data: TargetCodeReq & CodesReq,
  code: CodeReq
): any {
  return axios({
    url: `/projects/${code}/process-definition/batch-move`,
    method: 'post',
    data
  })
}

export function getTaskListByDefinitionCodes(
  params: CodesReq,
  code: number
): any {
  return axios({
    url: `/projects/${code}/process-definition/batch-query-tasks`,
    method: 'get',
    params
  })
}

export function importProcessDefinition(data: FormData, code: number): any {
  return axios({
    url: `/projects/${code}/process-definition/import`,
    method: 'post',
    data
  })
}

export function queryList(code: CodeReq): any {
  return axios({
    url: `/projects/${code}/process-definition/list`,
    method: 'get'
  })
}

export function queryProcessDefinitionByName(
  params: NameReq,
  code: CodeReq
): any {
  return axios({
    url: `/projects/${code}/process-definition/query-by-name`,
    method: 'get',
    params
  })
}

export function querySimpleList(code: number): any {
  return axios({
    url: `/projects/${code}/process-definition/simple-list`,
    method: 'get'
  })
}

export function verifyName(
  params: { name: string; workflowCode?: number },
  projectCode: number
): any {
  return axios({
    url: `/projects/${projectCode}/process-definition/verify-name`,
    method: 'get',
    params
  })
}

export function queryProcessDefinitionByCode(
  code: number,
  projectCode: number
): any {
  return axios({
    url: `/projects/${projectCode}/process-definition/${code}`,
    method: 'get'
  })
}

export function updateProcessDefinition(
  data: ProcessDefinitionReq & ReleaseStateReq,
  code: number,
  projectCode: number
): any {
  return axios({
    url: `/projects/${projectCode}/process-definition/${code}`,
    method: 'put',
    data
  })
}


export function getTasksByDefinitionList(
  projectCode: number,
  processCode: number
): any {
  return axios({
    url: `/projects/${projectCode}/process-definition/query-task-definition-list`,
    method: 'get',
    params: {
      processDefinitionCode: processCode
    }
  })
}





